/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kedacom.demo.jmx.book;

import javax.management.MBeanException;

/**
 *
 * @author Administrator
 */
public class ExceptionUtil {

    public static void printException(Exception e) {

        StringBuffer exceptionName = new StringBuffer();

        Exception exc = null;

        System.out.println("-------[ Exception ]-------");

        e.printStackTrace();



        if (e instanceof MBeanException) {

            boolean hasEmbeddedExceptions = true;

            Exception embeddedExc = e;

            while (hasEmbeddedExceptions) {

                embeddedExc = ((MBeanException) embeddedExc).getTargetException();

                System.out.println("-------[ Embedded Exception ]-------");

                embeddedExc.printStackTrace();



                if (!(embeddedExc instanceof MBeanException)) {

                    hasEmbeddedExceptions = false;

                }

            }

        }
    }
}
